package org.attached.user.controller;


import org.attached.user.entity.ChatUser;
import org.attached.user.service.ChatUserService;
import org.common.vo.ResponseReturn;
import org.common.vo.ServiceException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;



/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author Mr.古
 * @since 2018-05-05
 */
@RestController
@RequestMapping("/chatUser")
public class ChatUserController {

	@Autowired
	private ChatUserService userService;
	
	/**
	 * 获取用户信息
	 * @author Mr.古
	 * @param userName
	 * @return
	 */
	@PostMapping("/getUserDetail")
	public ResponseReturn<ChatUser> getUserDetail(String userName){
		return ResponseReturn.successful(userService.getUserDetail(userName));
	}
	
	/**
	 * 注册
	 * @author Mr.古
	 * @param chatUser
	 * @return
	 */
	@PostMapping("/register")
	public ResponseReturn<ChatUser> register(ChatUser chatUser){
		try {
			return ResponseReturn.successful(userService.register(chatUser));
		} catch (ServiceException e) {
			return ResponseReturn.error(e.getMessage());
		}
	}
	
	/**
	 * 登录
	 * @author Mr.古
	 * @param token
	 * @return
	 */
	@PostMapping("/login")
	public ResponseReturn<ChatUser> login(String token){
		try {
			return ResponseReturn.successful(userService.login(token));
		} catch (ServiceException e) {
			return ResponseReturn.error(e.getMessage());
		}
	}
}

